GBML manual / Screen

screen_blend

Changes how much of every see-through thing shows on each row of the screen: a dark room gets dark edges, a mist thins out toward the floor. look is one of the BLEND_ constants, strength (1 to 3) is how strong it is, and speed is how fast a moving look travels down the screen. BLEND_NONE turns it off. Give the optional last argument layer (ROOM_LAYER_MAIN, ROOM_LAYER_FRONT or ROOM_LAYER_BACK) to fade only that one tile layer of the room: screen_blend(BLEND_FADE_DOWN, 2, 0, ROOM_LAYER_BACK) fades the Back layer and leaves the Main and Front layers as they are. With no layer the look reaches everything it always did.

Works differently on Game Boy - On the Game Boy a see-through sprite is drawn on as many frames of 16 as the look says for its row, and a see-through background fades toward its backdrop shade in bands (at most 8, each 18 rows or more).

Works differently on Game Boy Color - On the Game Boy Color a see-through sprite is drawn on as many frames of 16 as the look says for its row, and a see-through background fades toward the backdrop by the look's average, the same on every row.

Sega Genesis: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

screen_blend(look, strength, speed, layer = ROOM_LAYER_ALL)

Arguments

NameType
lookblend_look
strengthint
speedreal
layerroom_layer (can be left out; then it is ROOM_LAYER_ALL)

Returns

Nothing.

Description

Changes how much of every see-through thing shows on each row of the screen. Some things are drawn so that you can see what is behind them: the dark of a dim room, a sheet of mist, a ghost. How much of the thing you see and how much of the picture behind it is a choice the console makes with two numbers. This call lets those numbers be different on every row. A dark room can have dark edges, a mist can thin out toward the floor, a shadow can roll down the screen.

A real capture, six pictures of the same pine forest at dusk with a striped lighthouse in a dark room - first with the room's even darkness, then with each of the five BLEND_ looks in turn at strength 2 (darkness thickest at the top, darkness thickest at the bottom, dark edges with a clear middle, bands of darkness, and stripes of darkness)A real capture, six pictures of the same pine forest at dusk with a striped lighthouse in a dark room - first with the room's even darkness, then with each of the five BLEND_ looks in turn at strength 2 (darkness thickest at the top, darkness thickest at the bottom, dark edges with a clear middle, bands of darkness, and stripes of darkness)
A real capture, six pictures of the same pine forest at dusk with a striped lighthouse in a dark room - first with the room's even darkness, then with each of the five BLEND_ looks in turn at strength 2 (darkness thickest at the top, darkness thickest at the bottom, dark edges with a clear middle, bands of darkness, and stripes of darkness)

A dark room first, with the same darkness on every row. Then each look at strength 2, standing still. Real pictures from a Game Boy Advance ROM.

You give it three things:

Which look

LookWhat it is
BLEND_FADE_DOWNall of the see-through thing at the top of the screen, fading away toward the bottom
BLEND_FADE_UPthe same upside down: all of it at the bottom, fading away toward the top
BLEND_VIGNETTEthe least across the middle of the screen, more and more toward the top and the bottom
BLEND_WAVEa smooth wave of strong and weak bands that rolls down the screen
BLEND_BLINDSstripes 8 rows tall, a strong one and a weaker one, like light through window blinds

What it changes

It changes the things that are see-through, and only those. That is five kinds of thing:

Everything else is drawn the way it always was. A blend look on a screen with nothing see-through changes nothing at all.

A dark room keeps its darkness

A dark room has a darkness of its own, a number you set in the room. A blend look does not throw that number away. The look is a shape laid on top of it: the screen is, on average, exactly as dark as the room says, and the look moves the darkness around - more of it in some rows, less in others. A room set to 20 gets a light version of the shape and a room set to 80 a heavy one, so the number you chose still matters when a look is on. No row can be darker than black, so in a very dark room a look that wants to be darker than that is held at black there.

In a room that is not dark there is no darkness to keep, so the look's own numbers are the whole story: that is how a mist background fades. (A marked background, a marked object and a blending particle effect share the dark room's numbers, because the console has just one pair. In a dark room they start from the room's darkness too.)

When you turn the look off, the room's own darkness comes back, exactly as it was.

One at a time

The console has just one pair of see-through numbers, so there is at most one blend look at a time. Asking for a different look, or the same look at a different strength, replaces the first one and keeps the pattern where it was. Asking again for the same look and strength only changes the speed, so a Step event that asks every frame does not restart anything.

Call it once

You do not need to call it every frame. Call it once - when the room starts is a good time - and the look keeps going by itself. A look belongs to the screen, so there is nothing to remember and nothing to lose: the look ends by itself when a room is loaded (you change room, or restart the one you are in), so a new room that wants a pattern asks for its own.

Turning it off

screen_blend(BLEND_NONE, 0, 0);

This gives its slot back straight away. The last two numbers are ignored, but they have to be there.

Always destroy it, do not hide it. There is no way to hide a look, on purpose: something hidden would look gone but would still be using up one of the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why. Off always means the slot is free.

What it costs

A blend look uses one of the 8 row-by-row effects the console has, and no matrix and no sprite. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row: screen_backdrop, draw_sprite_ripple, sprite_warp and the others. You can see how many are in use on the debug screen: the line called H-BLANK.

The patterns live in the cartridge: a few hundred bytes each, and a call that names its look keeps only that one. The 160 rows the console reads are worked out into 1,280 bytes of memory. Measured on a real ROM, a look that stands still costs about 1 hundredth of a frame, and one that moves costs about 3 hundredths, because its rows are worked out again every frame it moves.

When there is no room

Ask for more than there is and the game does not skip it. A development build stops with a message that says how many slots there are and names every look that is holding one, so you know which one to turn off. A release build, which has no way to stop and show a message, draws everything with no look. It never half-works.

Example

screen_blend(BLEND_VIGNETTE, 2, 0);

A dark room with dark edges and a clear middle. Call it in the room's Create code, in a room that is set to be dark. The room keeps its darkness: the screen is as dark, on average, as the number you set.

A mist that thins out toward the floor needs a background to be the mist:

mist = background_create(0, 0, ts_doc_dungeon);
background_see_through(mist, true);
background_priority(mist, 0);
screen_blend(BLEND_FADE_DOWN, 2, 0);

The background is marked see-through, brought in front of everything with background_priority, and the blend look makes it thick at the top and thin at the bottom.

One tile layer

Give it a fourth number, the layer, and only that one tile layer of the room is made see-through, row by row: ROOM_LAYER_MAIN, ROOM_LAYER_FRONT or ROOM_LAYER_BACK. The layer is marked see-through for you, and the other layers are drawn as they are. With no layer the call is the call it always was. A room that does not have that layer does nothing. Because the console has one pair of see-through weights, the look is still one look for the whole screen: if two layers are faded they show the same look. In the Room Editor, the Effect of a tile layer (Fade) writes this call for you and the canvas plays it live.

screen_blend(BLEND_FADE_DOWN, 2, 0, ROOM_LAYER_BACK);

Fades the Back layer from solid at the top to see-through at the bottom, and leaves the Main and Front layers as they are.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the look is on, and no matrix and no sprite. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. The console has just ONE pair of see-through weights, so there is at most one blend look at a time: asking for a different look or strength replaces the first, and asking again for the same look and strength only changes the speed. It works on what is see-through: a shrouded room’s dark layer (its shroud), a background you marked with background_see_through, an object you marked with sprite_see_through (everything it draws, text too), the tiles of a room whose Tile fade (Room Properties) is not None, and a particle effect set to ALPHA blend in a room that is not dark. Everything else is drawn as it always was. In a dark room the look keeps the room’s own darkness: it is a shape laid on the number you set, so the screen is on average exactly as dark as the room says, and the look moves the darkness around (no row is darker than black). In a room that is not dark, the look’s rows are the weights, so a marked background shows a mist. The tables are in the cartridge (a few hundred bytes each; a call with a look written out keeps only that one), the 160 rows the console reads are worked out into 1,280 bytes of its big, slow memory (EWRAM), and again every frame a moving look moves (about 3 hundredths of a frame each time). A look stays until you turn it off or a room is loaded (a restart counts). Turning it off with BLEND_NONE hands the slot back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one, a development build stops with a message that names every look holding a slot; a release build draws everything with no look. The in-game debug overlay shows the count as H-BLANK.

See also: background_see_throughsprite_see_throughscreen_mosaicscreen_scanlinesscreen_backdropParticles and lighting